package cn.laixueit.source;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author duxiang
 * @date 2024/3/6 15:33
 */

public abstract class BaseController<S extends IService<T>,T>{
    @Autowired
    private S baseService;

    public Boolean save(T t){
        return baseService.save(t);
    }

    public Boolean update(T t){
        return baseService.updateById(t);
    }

    public Boolean remove(T t){
        return baseService.removeById(t);
    }

    public T get(T t){
        return baseService.lambdaQuery().setEntity(t).one();
    }

    public List<T> list(T t){
        return baseService.lambdaQuery().setEntity(t).list();
    }

    public IPage<T> page(Integer page,Integer size, T t){
        Page<T> tPage = new Page<>(page, size);
        return baseService.lambdaQuery().setEntity(t).page(tPage);
    }
}
